<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>个人中心菜单列表</title>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body style="padding: 15px">
<div style="float: left;margin-right: 10px;margin-bottom: 10px">
    <input type="hidden" name="pid" value="{{ $pmenu?$pmenu['mid']:'0' }}">
    <button class="layui-btn" onclick="add()">添加</button>
</div>

@if(isset($pmenu['mid']) && $pmenu['mid']>0)
    <button class="layui-btn layui-btn-primary" onclick="backup({{ $pmenu['pid'] }})">返回【{{ $pmenu['title'] }}】</button>
@endif

<table class="layui-table">
    @csrf
    <thead>
    <tr>
        <th>ID</th>
        <th>排序</th>
        <th>菜单名称</th>
        <th>控制器</th>
        <th>方法</th>
        <th>是否隐藏</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    @foreach($menus as $item)
        <tr>
            <td>{{ $item['mid'] }}</td>
            <td>{{ $item['ord'] }}</td>
            <td>{{ $item['title'] }}</td>
            <td>{{ $item['controller'] }}</td>
            <td>{{ $item['action'] }}</td>
            <td>{{ $item['ishidden']?'隐藏':'正常' }}</td>
            <td>{{ $item['status']?'禁用':'启用' }}</td>
            <td>
                <button class="layui-btn layui-btn-xs layui-btn-primary" onclick="childs({{$item['mid']}})">下级菜单</button>
                <button class="layui-btn layui-btn-xs" onclick="edit({{ $item['mid'] }})">编辑</button>
                <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({{ $item['mid'] }})">删除</button>
            </td>
        </tr>
    @endforeach

    </tbody>
</table>
<div id="pages"></div>
<script type="text/javascript">
    layui.use(['layer','laypage'],function(){
        layer = layui.layer;
        $ = layui.jquery;
        laypage = layui.laypage;

        //分页参数
        laypage.render({
            elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
            ,limit: {{ $pageSize }}
            ,count: {{ $total }} //数据总数，从服务端得到
            ,curr: {{ $page }}
            ,layout:['prev','page','next','skip','count']
            ,jump: function(obj, first){
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。


                //首次不执行
                if(!first){
                    window.location.href = '?page='+obj.curr;
                }
            }
        });
    });

    // 添加菜单
    function add(){
        var pid = $('input[name="pid"]').val();
        layer.open({
            type: 2,
            title: '添加菜单',
            shadeClose: true,
            shade: 0.8,
            area: ['580px', '450px'],
            content: '/admin/member/member_add?pid='+pid
        });
    }

    // 编辑菜单
    function edit(mid){
        layer.open({
            type: 2,
            title: '编辑菜单',
            shadeClose: true,
            shade: 0.8,
            area: ['580px', '450px'],
            content: '/admin/member/member_edit?mid='+mid
        });
    }

    // 子菜单
    function childs(mid){
        window.location.href="?mid="+mid;
    }

    // 返回上一级
    function backup(ppid){
        window.location.href="?mid="+ppid;
    }


    // 删除菜单
    function del(mid){
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['删除','取消']
        }, function(){
            var _token = $('input[name="_token"]').val();
            $.post('/admin/member/member_del',{mid:mid,_token:_token},function(res){
                if(res.code>0){
                    return layer.alert(res.msg,{icon:2});
                }
                layer.msg(res.msg);
                setTimeout(function(){window.location.reload();},1000);
            },'json');
        });
    }
</script>
</body>
</html>
